package com.example.administrator.printoutindemo;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import com.dds.soap.SoapListener;
import com.dds.soap.SoapParams;
import com.example.administrator.printoutindemo.base.BaseActivity;
import com.example.administrator.printoutindemo.http.SPUtil;
import com.jess.arms.base.BaseConstants;

import org.ksoap2.SoapFault;
import org.ksoap2.serialization.SoapObject;

public class TiaoZhuanJiageweihuActivity extends BaseActivity {
    private TextView tv_sqrss, tv_cxss, tv_rwmsss, tv_ysss, tv_buchong;
    private EditText et_sjss;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.tianjiajiage);
        tv_sqrss = findViewById(R.id.tv_sqrss);
        tv_cxss = findViewById(R.id.tv_cxss);
        tv_rwmsss = findViewById(R.id.tv_rwmsss);
        tv_ysss = findViewById(R.id.tv_ysss);
        tv_buchong = findViewById(R.id.tv_buchong);
        et_sjss = findViewById(R.id.et_sjss);
        tv_sqrss.setText(SPUtil.getString(TiaoZhuanJiageweihuActivity.this, "sqr", ""));
        tv_cxss.setText(SPUtil.getString(TiaoZhuanJiageweihuActivity.this, "chexing", ""));
        tv_rwmsss.setText(SPUtil.getString(TiaoZhuanJiageweihuActivity.this, "rwms", ""));
        tv_ysss.setText(SPUtil.getString(TiaoZhuanJiageweihuActivity.this, "yusuan", ""));
        tv_buchong.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                updateActualCost();
            }
        });
    }

    private void updateActualCost() {


        String methodName = "UpdateActualCost";

        SoapParams params = new SoapParams();
        params.put("deliveryId", SPUtil.getString(TiaoZhuanJiageweihuActivity.this, "peisongids_ld", ""));
        params.put("actualCost", et_sjss.getText().toString());
        /**
         * 请求
         */
        soapUtil.callEntry(getUrl(), BaseConstants.NAME_SPACE, methodName, params, new SoapListener() {
            @Override
            public void onSuccess(int statusCode, SoapObject object) {

                String result = object.getProperty(methodName + "Result").toString();
                if (result != null && !result.equals("[]") && !result.equals("anyType{}") && !result.equals("Error") && !result.equals("-100")) {
                    int b = Integer.parseInt(result);
                    if (b == 1) {
                        Toast.makeText(TiaoZhuanJiageweihuActivity.this, "提交补充价格成功", Toast.LENGTH_LONG).show();
                    }
                } else {

                }

            }

            @Override
            public void onFailure(int statusCode, String content, Throwable error) {
            }

            @Override
            public void onFailure(int statusCode, SoapFault fault) {
            }
        }, getAapiUserName(), getApiPwd());
    }
}
